import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-09-08
 * Time: 9:35
 */
public class demo1 {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //要执行的任务
                System.out.println("Hello1");
            }
        }, 3000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //要执行的任务
                System.out.println("Hello2");
            }
        }, 2000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                //要执行的任务
                System.out.println("Hello3");
            }
        }, 1000);
        Thread.sleep(4000);
        timer.cancel();
    }

}
